﻿using CloudMusic.Helper;
using CloudMusic.Model;
using CloudMusic.ViewModel;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using TagLib.Ape;

namespace CloudMusic.View
{
    /// <summary>
    /// PageBoutiqueSheet.xaml 的交互逻辑
    /// </summary>
    public partial class PageBoutiqueSheet : Page
    {
        public PageBoutiqueSheet(PageBoutiqueSheetViewModel pb)
        {
            InitializeComponent();
            this.DataContext = pb;
            this.SizeChanged += PageBoutiqueSheet_SizeChanged;
        }

        private void PageBoutiqueSheet_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            var fm = DataContext as PageBoutiqueSheetViewModel;
            if (this.ActualWidth > 822)
            {
                fm.BoutColuns = 3;
            }
            else
            {
                fm.BoutColuns = 2;
            }
        }

        private void heardImg_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Image item = (Image)sender;
            Boutique b = (Boutique)item.DataContext;;
            Goto(b.SheetId);
        }

        private void arName_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            MessageBox.Show("2");
        }
        private void title_name_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            TextBlock item = (TextBlock)sender;
            Boutique b = (Boutique)item.DataContext;
            Goto(b.SheetId);

        }
        private void Goto(long id)
        {
            var ps = new PageSongSheetDetailViewModel(id, 2);
            PageSongSheetDetail pageSongSheetDetail = new PageSongSheetDetail(ps, id, 2);
            NavigationService.Navigate(pageSongSheetDetail);
        }
        private void jpList_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
        {
            CommonHelper.RunScorllView(sender, e);
        }

        private void sc_ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            ScrollViewer scroll = (ScrollViewer)sender;
            if (scroll.VerticalOffset == sc.ActualHeight)
            {
                var item = itemsControl.Items;
                Boutique bq = (Boutique)item[item.Count - 1];
                string tag = tagType.Content.ToString();
                new PageBoutiqueSheetViewModel(tag, bq.Time);
            }
        }
    }
}
